package com.zx.task.manager.mapstruct;

import com.zx.task.manager.enums.TaskPriorityEnum;
import com.zx.task.manager.enums.TaskSeverityEnum;
import com.zx.task.manager.enums.TaskStatusEnum;
import com.zx.task.manager.model.Tasks;
import com.zx.task.manager.param.TasksParam;
import com.zx.task.manager.vo.TasksVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

/**
 * <p>
 * description: 任务信息映射 <br>
 * create: 2025-10-13 20:15
 * </p>
 *
 * @author zhou  xun
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TasksMapStructMapper {
    TasksMapStructMapper INSTANCE = Mappers.getMapper(TasksMapStructMapper.class);

    /**
     * 将TasksParam转换为Tasks实体
     *
     * @param tasksParam 任务参数
     * @return Tasks实体
     */
    Tasks tasksParamToTasks(TasksParam tasksParam);

    /**
     * 将Tasks实体转换为TasksVO视图对象
     *
     * @param tasks 任务实体
     * @return TasksVO视图对象
     */
    TasksVO tasksToTasksVO(Tasks tasks);

    /**
     * 在映射完成后，设置描述性字段
     *
     * @param tasks   任务实体
     * @param tasksVO 任务VO
     */
    @AfterMapping
    default void setDescriptions(Tasks tasks, @MappingTarget TasksVO tasksVO) {
        // 设置优先级描述
        TaskPriorityEnum priorityEnum = TaskPriorityEnum.getEnumByCode(tasks.getPriority());
        if (priorityEnum != null) {
            tasksVO.setPriorityDesc(priorityEnum.getDesc());
        }

        // 设置状态描述
        TaskStatusEnum statusEnum = TaskStatusEnum.getEnumByCode(tasks.getStatus());
        if (statusEnum != null) {
            tasksVO.setStatusDesc(statusEnum.getDesc());
        }

        // 设置严重程度描述
        TaskSeverityEnum severityEnum = TaskSeverityEnum.getEnumByCode(tasks.getSeverity());
        if (severityEnum != null) {
            tasksVO.setSeverityDesc(severityEnum.getDesc());
        }
    }
}